<template>
    <a-drawer v-model:visible="LAYER.visible" :title="LAYER.title" :width="LAYER.width"
              :closable="LAYER.closable" :mask-closable="LAYER.maskClosable" :esc-to-close="LAYER.escToClose"
              :unmount-on-close="LAYER.unmountOnClose" :footer="LAYER.footer" :ok-text="LAYER.okText"
              :ok-loading="LAYER.okLoading" :cancel-text="LAYER.cancelText" :on-before-ok="onSubmit" @close="onCancel">
        <a-form ref="formRef" :model="formState" layout="vertical" :rules="ACCOUNT_ALIPAY_EDIT.RULES">
            <a-row :gutter="12">
                <a-col :span="12">
                    <a-form-item label="应用类型" field="appType">


                        <smart-dict :url="DictOptions.AppType" v-model="formState.appType" placeholder="请设置接入支付宝的应用类型" :disabled="isUpdate"/>
                    </a-form-item>
                </a-col>




                <a-col :span="12">
                    <a-form-item label="应用ID" field="appId">
                        <a-input v-model="formState.appId" allow-clear placeholder="请设置接入支付宝应用ID"/>
                    </a-form-item>
                </a-col>









                <a-col :span="12">
                    <a-form-item label="支付宝公钥" field="publicKey">
                        <a-textarea v-model="formState.publicKey" :auto-size="{minRows:2 , maxRows:5}" allow-clear placeholder="请设置证书内容"/>
                    </a-form-item>
                </a-col>


                <a-col :span="12">
                    <a-form-item label="应用私钥" field="privateKey">
                        <a-textarea v-model="formState.privateKey" :auto-size="{minRows:2 , maxRows:5}" allow-clear placeholder="请设置证书秘钥"/>
                    </a-form-item>
                </a-col>

              <a-col :span="12">
                <a-form-item label="应用私钥" field="sandbox">
                  <smart-bool v-model="formState.sandbox" true-text="沙箱环境" false-text="真实环境"/>

                 </a-form-item>
              </a-col>


              <a-col :span="12">
                <a-form-item label="签名算法" field="signType">
                  <a-radio-group v-model="formState.signType">
                    <a-radio value="RSA">RSA</a-radio>
                    <a-radio value="RSA2">RSA2</a-radio>

                  </a-radio-group>





                </a-form-item>
              </a-col>



                <a-col :span="24">
                    <a-form-item label="备注信息" field="description">
                        <a-textarea v-model="formState.description" :auto-size="{minRows:2 , maxRows:5}" allow-clear placeholder="备注信息"/>
                    </a-form-item>
                </a-col>


            </a-row>


        </a-form>
        <!--表单结束-->
    </a-drawer>
</template>

<script lang="ts" setup>

import {EditDrawer} from '@/libs/core'

import {ACCOUNT_ALIPAY_EDIT} from "../resource/form";
import {SystemHttp} from '../resource/http'
import {DictOptions} from "@/libs/options";

const props = defineProps({record: {type: Object, required: true}})
const emit = defineEmits(['cancel'])

const {addAlipay, updateAlipay} = SystemHttp
const config = {tplRecord: ACCOUNT_ALIPAY_EDIT.BODY, rawRecord: props.record, rowKey: 'id', emit}

const service = new EditDrawer(config).setAddRequest(addAlipay).setUpdateRequest(updateAlipay)
const {formRef, formState, LAYER, isUpdate, onCancel, onSubmit} = service
LAYER.title = isUpdate ? '修改支付宝' : '新建支付宝'
</script>
